// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'

Vue.config.productionTip = false

import '@/assets/css/base.css'

import ElementUI from 'element-ui'  //使用element-ui
import 'element-ui/lib/theme-chalk/index.css'  //单独引入样式文件
Vue.use(ElementUI)  //vue使用element-ui

import ajaxs from "./request/request"  //导入封装的axios
Vue.prototype.$http = ajaxs  //挂载到vue实例上 通过this.$http 执行ajax请求


/*
// 图片公共路径
*/
// 测试
// Vue.prototype.urlimg = 'http://krypton.qiniu.isartop.com/'

// 正式
Vue.prototype.urlimg = 'http://sybg.qiniu.isartop.com/'


// 测试   外连接
// Vue.prototype.urlwlj = 'http://sybg.comeinvip.com/#/'

// 正式   外连接
Vue.prototype.urlwlj = 'http://fyyp.9colordeer.com/#/'


// 测试   外连接
// Vue.prototype.urlwlj1  = 'http://center.sybg.comeinvip.com/#/'

// 正式   外连接
Vue.prototype.urlwlj1 = 'http://center.9colordeer.com/#/'

// 测试   打包域名
// Vue.prototype.upwebpack = 'sybg_dev'

// 正式   外连接
Vue.prototype.upwebpack = 'sybg'


Vue.prototype.variable_name1 = '蜜贝'
Vue.prototype.variable_number1 = 'Fmb'

Vue.prototype.variable_name2 = '金蜜'
Vue.prototype.variable_number2 = 'Ghy'

Vue.prototype.variable_name3 = '蜂钻'

Vue.prototype.variable_name4 = '蜂巢'

Vue.prototype.variable_kind1 = '优选日用品'
Vue.prototype.variable_kind2 = '严选新生鲜'
Vue.prototype.variable_kind3 = '美妆轻服饰'
Vue.prototype.variable_kind4 = '蜂盈合伙人'
Vue.prototype.variable_kind5 = '蜂巢合伙人'



//使用富文本
import  VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)

// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

// 引入颜色选择器
import vcolorpicker from 'vcolorpicker'
Vue.use(vcolorpicker)

//使用图片截取
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)

/*
//post 封装his.$http
*/
Vue.prototype.post = function(url, data) {

  if (data == null) {   //传入data
		data = {}
  }
   let  token = null;
  //  token = localStorage.getItem('my_token_fen');
  token = sessionStorage.getItem('session_token');

   if (token != null) {
		data.token = token
	}

  return new Promise((resolve,reject) => {

    this.$http({
      method:"post",
      url:url,
      data:data
     }).then(res => {

      if(res.error_code == 301){ //请重新登录回到login页面
        this.$router.push('/login')
      }
      resolve(res)

     }).catch(error => {

      reject(error)

      })

  })


}

/*
//图片单张上传ajax
*/
Vue.prototype.upimgpost = function(url, data) {

   let  token = null;
  //  token = localStorage.getItem('my_token_fen');
  token = sessionStorage.getItem('session_token');
	 let formData = new FormData();
   formData.append('token',token);
   formData.append('file',data);

  return new Promise((resolve,reject) => {

    this.$http({
      method:"post",
      url:url,
      data:formData
     }).then(res => {

      if(res.error_code == 301){ //请重新登录回到login页面
        this.$router.push('/login')
      }
      resolve(res)

     }).catch(error => {

      reject(error)

      })

  })

}

/*
//图片单张上传图片格式拦截
*/

Vue.prototype.upimglx = function(file){
  var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
  const extension = testmsg === "jpg" || testmsg === "JPG" || testmsg === "png" || testmsg === "PNG";
  if (!extension) {
     //this.open1("上传图片只能是jpg/png 格式!",'warning')  //提示框
     return false; //必须加上return false; 才能阻止
   }
}

/*
//图片上传错误提示
*/

Vue.prototype.upimglxtitle = function(){
  this.open1("上传图片只能是jpg/png 格式!",'warning')
}




/*
//带进度条的文件上传
*/
Vue.prototype.upimgpost1 = function(url, data,phone) {
  let than = this
  let  token = null;
  // token = localStorage.getItem('my_token_fen');
  token = sessionStorage.getItem('session_token');
  let formData = new FormData();
  formData.append('token',token);
  formData.append('file',data);
  formData.append('smscode',phone);

 return new Promise((resolve,reject) => {

   this.$http({
     method:"post",
     url:url,
     data:formData,
     onUploadProgress(progressEvent) {
          than.progressPercent = Number((progressEvent.loaded / progressEvent.total * 100).toFixed(2))
         //console.log(Number((progressEvent.loaded / progressEvent.total * 100).toFixed(2)))
     }
    }).then(res => {

     if(res.error_code == 301){ //请重新登录回到login页面
       this.$router.push('/login')
     }
     resolve(res)

    }).catch(error => {

     reject(error)

     })

 })

}

/*
// 包拦截
*/

Vue.prototype.upimglx1 = function(file){
  var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
  const extension = testmsg === "apk" || testmsg === "wgt"  ;
  if (!extension) {
     //this.open1("上传图片只能是jpg/png 格式!",'warning')  //提示框
     return false; //必须加上return false; 才能阻止
   }
}
/*
// 包提示拦截
*/
Vue.prototype.upimglxtitle1 = function(){
  this.open1("上传图片只能是apk/wgt 格式!",'warning')
}

// 获取验证码
// Vue.prototype.getCode = function(){
//       let than =this
//       than.disabled = true
//       var codeText = this.codeText
//       var clock = setInterval(function() {
//         than.totalTime--
//         than.codeText = than.totalTime + 's'
//         if (than.totalTime == 1) {
//           clearInterval(clock);
//           than.codeText = codeText
//           than.totalTime = 60
//           than.disabled = false
//         }
//       }, 1000)
// }

/*
获取当前日期
*/
Vue.prototype.getNowDate = function() {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month;
  return currentdate;

}

/*
获取当前日期带日的  yyyy-MM-dd
*/
Vue.prototype.getNowDate1 = function() {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;

}


/*
获取明天日期带日的  yyyy-MM-dd
*/
Vue.prototype.getNowDate_tomorrow = function() {
  var day = new Date();
  day.setTime(day.getTime() + 24 * 60 * 60 * 1000); //加上一天的秒数
  var seperator1 = "-";
  var year = day.getFullYear();
  var month = day.getMonth() + 1;
  var strDate = day.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;

}
/*
获取当前日期带日的  yyyy
*/
Vue.prototype.getNowDate2 = function() {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();

  var currentdate = year;
  return currentdate;

}


/*
获取当前日期带日的  yyyy-MM
*/
Vue.prototype.getNowDate3 = function() {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month;
  return currentdate;

}

/*
时间戳转化  yyyy-MM-dd
*/
Vue.prototype.getNowDateSjc = function(date) {
  var date = new Date(date);
  var YY = date.getFullYear() + '-';
  var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  // return YY + MM + DD +" "+hh + mm + ss;
  return YY + MM + DD ;
}


/**
 * 验证手机号
 */
Vue.prototype.checkPhone = function(phone) {
	if (!(/^1[3456789]\d{9}$/.test(phone))) {
		return false;
	} else {
		return true;
	}
}

/**
 * 验证input 输入只能是正整数
 */
Vue.prototype.proving1 = function(e) {
  var numReg = /^[0-9]*$/
  var numRe = new RegExp(numReg)
  if (!numRe.test(e.target.value)) {
       this.open1('输入不能为小数获负数','warning')
       e.target.value = ''
  }
}

/**
 * 验证邮箱
 */
Vue.prototype.checkEmail = function(email) {
	if (!(/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/.test(email))) {
		return false;
	} else {
		return true;
	}
}


/*
// 提示框函数 ts_title 传入内容  ts_type 传入类型
*/
Vue.prototype.open1 = function(ts_title,ts_type) {
   let that = this
   this.$message({
    message: ts_title ,
    type: ts_type
  });
}

/*
// 表格单双颜色变化函数
*/
Vue.prototype.tableRowClassName = function({row, rowIndex}) {
  if(rowIndex%2==1){
    return 'warning-row';
  }else{
    return 'success-row';
  }

}

/*
//视频格式拦截
*/

Vue.prototype.upvideolx = function(file){
  var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
  const extension = testmsg === "mp4";
  if (!extension) {
     //this.open1("上传图片只能是jpg/png 格式!",'warning')  //提示框
     return false; //必须加上return false; 才能阻止
   }
}

/*
//视频上传错误提示
*/

Vue.prototype.upvideolxtitle = function(){
  this.open1("视频只能上传mp4格式",'warning')
}

/*
//二级密码/和验证码验证
*/
Vue.prototype.getCode_yz = function(){
  let than =this
  than.user_test.disabled = true
  this.post("/account/checkSafePwd", {
               password:this.user_test.password
           }).then(res => {

               if(res.error_code == 0){

                   if(res.result == false){
                        than.user_test.disabled = false
                        this.open1('二级密码不正确','warning')
                   }else if(res.result == true){
                         this.post("/account/getSmsCodeForCheck", {
                         }).then(res => {
                               this.open1('发送成功','success')
                               than.user_test.disabled = true
                               var codeText = this.user_test.codeText
                               var clock = setInterval(function() {
                               than.user_test.totalTime--
                               than.user_test.codeText = than.user_test.totalTime + 's'
                               if (than.user_test.totalTime == 1) {
                                   clearInterval(clock);
                                   than.user_test.codeText = codeText
                                   than.user_test.totalTime = 60
                                   than.user_test.disabled = false
                               }
                               }, 1000)

                           })
                   }

               }else {
                    than.user_test.disabled = false
                    this.open1('请输入二级密码','warning')
               }

   })
}

/*
//二级密码/和验证码验证 确认按钮
*/
Vue.prototype.getCode_yz_qr = function(){
  let than =this
  return new Promise((resolve,reject) => {

      this.post("/account/checkSmsCodeForCheck", {
        smscode:than.user_test.phone
       }).then(res => {

          if(res.error_code == 0){

              if(res.result == true){
                than.open1(res.result,'success')  //提示框
                than.user_test.password = ''
                than.user_test.phone = ''
                than.user_test.user_mtk = false
                resolve(1)

              }else if(res.result == false){
                resolve(0)
                than.open1('验证码不正确','warning')  //提示框
              }

          }else {
            than.open1(res.message,'warning')
          }

      }).catch(error => {

        reject(error)

        })


  })


}


/*
//只有二级密码验证
*/

Vue.prototype.ej_but = function(){

  return new Promise((resolve,reject) => {

      this.post("/account/checkSafePwd", {
        password:this.user_test_a.password
      }).then(res => {

              if(res.error_code == 0){

              if(res.result == false){
                this.open1('二级密码不正确','warning')
                resolve(0)
              }else if(res.result == true){
                this.open1('成功','success')
                resolve(1)
              }

              }else {
              this.open1('请输入二级密码','warning')
              }

      }).catch(error => {

        reject(error)

      })

  })

}


/*
//只有短信验证
*/
Vue.prototype.ej_but1 = function(){

  let than =this
  than.user_test.disabled = true


  this.post("upgrade/getSmsCode", {
  }).then(res => {
        this.open1('发送成功','success')
        than.user_test.disabled = true
        var codeText = this.user_test.codeText
        var clock = setInterval(function() {
        than.user_test.totalTime--
        than.user_test.codeText = than.user_test.totalTime + 's'
        if (than.user_test.totalTime == 1) {
            clearInterval(clock);
            than.user_test.codeText = codeText
            than.user_test.totalTime = 60
            than.user_test.disabled = false
        }
        }, 1000)

    })



}

/*
//时间转化为秒12:00
*/
Vue.prototype.getTime = function(time){
    var hour = time.substring(0,2)
    var minutes  = time.slice(-2)
    hour = parseInt(hour)
    minutes = parseInt(minutes)
    var all_number = hour*60*60 + minutes*60
    return all_number
}

/*
// 获取当前时间 12:00
*/
Vue.prototype.getTime_fm = function(){
    var d = new Date();
    var my_hours=d.getHours();
    var my_minutes=d.getMinutes();
    var my_seconds=d.getSeconds();
    if (my_hours >= 0 && my_hours <= 9) {
      my_hours = "0" + my_hours;
    }
    if (my_minutes >= 0 && my_minutes <= 9) {
      my_minutes = "0" + my_minutes;
    }
    return  my_hours+":"+my_minutes
}

/*
// 时间戳转换 1354564 转 12：13
*/
Vue.prototype.getTime_time = function(value){
  var theTime = parseInt(value);// 秒
    var theTime1 = 0;// 分
    var theTime2 = 0;// 小时
    if(theTime > 60) {
        theTime1 = parseInt(theTime/60);
        theTime = parseInt(theTime%60);
            if(theTime1 > 60) {
            theTime2 = parseInt(theTime1/60);
            theTime1 = parseInt(theTime1%60);
            }
       }
        // var result = ""+parseInt(theTime)+"秒";
        var result = "";
        console.log(theTime1)
        if(0 < theTime1 && theTime1<10){
           result = ""+'0'+parseInt(theTime1)+result;
        }else if(theTime1 >= 10) {
           result = ""+parseInt(theTime1)+result;
        }else {
          result = ""+'00'+result;
        }
        if(theTime2 > 0) {
           result = ""+parseInt(theTime2)+":"+result;
        }
    return result;
}



/*
// 日期转时间戳 1354564 转 12：13
*/
Vue.prototype.getTime_date = function(value){
  let d = new Date(value)
  let t = d.getTime(d) // 方法1
  return t;
}

// 时间戳转化为 yy-dd-mm 12:30:30
Vue.prototype.getymdhms = function(timestamp){
  let time = new Date(timestamp)
  let year = time.getFullYear()
  let month = time.getMonth() + 1
  let date = time.getDate()
  let hours = time.getHours()
  let minute = time.getMinutes()
  let second = time.getSeconds()

  if (month < 10) { month = '0' + month }
  if (date < 10) { date = '0' + date }
  if (hours < 10) { hours = '0' + hours }
  if (minute < 10) { minute = '0' + minute }
  if (second < 10) { second = '0' + second }
  return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
}

//es6 时间戳转化为 yy-dd-mm 12:30:30
Vue.prototype.getymdhms1 = function(timestamp){
  let time = new Date(timestamp)
  let year = time.getFullYear()
  const month = (time.getMonth() + 1).toString().padStart(2, '0')
  const date = (time.getDate()).toString().padStart(2, '0')
  const hours = (time.getHours()).toString().padStart(2, '0')
  const minute = (time.getMinutes()).toString().padStart(2, '0')
  const second = (time.getSeconds()).toString().padStart(2, '0')

  return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
}


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
